<?php include("includes/connect_db.php"); ?>

<style>
	.table{
		border: 1px solid #DDD;
	}
	.tr-header{
		background-color: #0088cc; 
		color: #FFF;
	}
</style>

<?php
	$id_host = $_POST['id'];
	$nama_tabel = $_POST['namaTabel'];

	$sql_lihat_host = "SELECT * FROM tb_host WHERE id_host = '$id_host'";
	$query_lihat_host = mysql_query($sql_lihat_host);
	$lihat_host = mysql_fetch_array($query_lihat_host);

	$koneksiBaru = mysql_connect($lihat_host['host'], $lihat_host['username'], $lihat_host['password']) or die("Connection Error: " . mysql_error());

	mysql_select_db($lihat_host['db'], $koneksiBaru) or die("Error conecting to db.");
?>

<table class="table table-bordered" style="width: 100%">
	<tr class="tr-header">
		<?php
			$sql_lihat_info = "DESC $nama_tabel";
			$query_lihat_info = mysql_query($sql_lihat_info, $koneksiBaru);
			while ($lihat_info = mysql_fetch_array($query_lihat_info)) {
		?>
		<td><?php echo $lihat_info[0]; ?></td>
		<?php
			}
		?>
	</tr>
		<?php
			$sql_lihat_data = "SELECT * FROM $nama_tabel";
			$query_lihat_data = mysql_query($sql_lihat_data);

			
			while ($lihat_data = mysql_fetch_array($query_lihat_data)) {
				$temp = 0;
				echo "<tr>";

				$sql_lihat_info = "DESC $nama_tabel";
				$query_lihat_info = mysql_query($sql_lihat_info, $koneksiBaru);
				while ($lihat_info = mysql_fetch_array($query_lihat_info)) {
					echo "<td>";
					echo substr($lihat_data[$temp], 0, 20);
					if (strlen($lihat_data[$temp]) > 20) {
						echo "...";
					}
					echo "</td>";
					$temp++;
				}
				echo "</tr>";
			}
		?>
</table>
